package switchviz.gui.component;

import javax.swing.DefaultListSelectionModel;

public class ToggleSelectionModel extends DefaultListSelectionModel
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 7478766484991709146L;
	boolean _gestureStarted = false;
    
    public void setSelectionInterval(int index0, int index1) 
    {
		if (isSelectedIndex(index0) && !_gestureStarted) 
		    super.removeSelectionInterval(index0, index1);
		else 
		    super.addSelectionInterval(index0, index1);

		_gestureStarted = true;
    }

    public void setValueIsAdjusting(boolean isAdjusting) 
    {
		if (isAdjusting == false) 
		    _gestureStarted = false;
    }
}  